﻿using System;
using System.Collections.Generic;
using System.Drawing;

namespace RGBGame
{
    internal enum Colors
    {
        Transparent = 0,
        Red = 1,
        Green = 2,
        Blue = 3,
        ScoredOpponent = 4,
        ScoredYou = 5,
        OutOfRange = 6
    };

    public class TilePoint
    {
        internal int X, Y;
        public TilePoint(int x, int y)
        {
            X = x;
            Y = y;
        }

        internal static TilePoint get(int i)
        {
            int y = i / 6;
            int x = i - (y * 6);
            return new TilePoint(x, y);
        }

        internal static int getY(int i)
        {
            return i / 6;
        }
    }

    public class Utility
    {

        internal static Dictionary<string, string> gameClients = new Dictionary<string, string>();
        internal static void BindSession(string sessionId, string clientId)
        {
            if (!string.IsNullOrEmpty(sessionId))
            {
                lock (Utility.gameClients)
                {
                    if (Utility.gameClients.ContainsKey(sessionId))
                    {
                        string oldClientId = Utility.gameClients[sessionId];
                        Room.RemovePlayer(oldClientId, oldClientId ,true);
                    }
                    Utility.gameClients[sessionId] = clientId;
                }
            }
        }

        private static Random rnd = new Random();

        internal static int getRandom()
        {
            lock (rnd)
            {
                return rnd.Next(1, 2 + (DateTime.Now.Millisecond%98));
            }
        }
        
        internal static Color getColor(Colors ch)
        {
            switch (ch)
            {
                case Colors.Red:
                    return Color.Maroon;
                    break;
                case Colors.Green:
                    return Color.YellowGreen;
                case Colors.Blue:
                    return Color.CornflowerBlue;
                    break;
                default:
                    return Color.Transparent;
                    break;
            }
        }
    }
}